﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QuanLyBanVeXe
{
    public partial class ReportVeXe : Form
    {
        public SqlConnection myConnection;
        public SqlCommand myCommand;
        
        public ReportVeXe()
        {
            InitializeComponent();
        }
        public static string maso = string.Empty;
        private void ReportVeXe_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsTuyenDi.QuanLyVe' table. You can move, or remove it, as needed.
            this.QuanLyVeTableAdapter.Fill(this.dsTuyenDi.QuanLyVe);
            cbbBenDi.DataSource = LayTuyenDi();
            cbbBenDi.DisplayMember = "BenDiBenDen";
            cbbBenDi.Text = null;
            dtTuNgay.Text = dtDenNgay.Text = "";
            this.rpvVeXe.RefreshReport();

        }
        public DataTable LayTuyenDi()
        {
            SqlConnection con = new SqlConnection(@"server=.\SQLEXPRESS; database=QuanLyBanVeXe; integrated security=true");
            DataTable dt = new DataTable();
            string sql = "select BenDiBenDen from TuyenDi";
            SqlDataAdapter da = new SqlDataAdapter(sql, con);
            da.Fill(dt);
            return dt;
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            txtTaiKhoan.Text = maso;
            if (dtTuNgay.Value.ToString("dd/MM/yyyy") == "01/01/0001" && dtDenNgay.Value.ToString("dd/MM/yyyy") == "01/01/0001")
                this.QuanLyVeTableAdapter.LayTen(this.dsTuyenDi.QuanLyVe, txtTaiKhoan.Text, cbbBenDi.Text);
            else
                if (dtTuNgay.Value.ToString("dd/MM/yyyy") != "01/01/0001" && dtDenNgay.Value.ToString("dd/MM/yyyy") == "01/01/0001")
                    this.QuanLyVeTableAdapter.TuNgay(this.dsTuyenDi.QuanLyVe, txtTaiKhoan.Text, cbbBenDi.Text, dtTuNgay.Value.ToShortDateString());
                else
                    if (dtTuNgay.Value.ToString("dd/MM/yyyy") == "01/01/0001" && dtDenNgay.Value.ToString("dd/MM/yyyy") != "01/01/0001")
                        this.QuanLyVeTableAdapter.DenNgay(this.dsTuyenDi.QuanLyVe, txtTaiKhoan.Text, cbbBenDi.Text, dtDenNgay.Value.ToShortDateString());
                    else
                        this.QuanLyVeTableAdapter.LayDuLieu(this.dsTuyenDi.QuanLyVe, txtTaiKhoan.Text, cbbBenDi.Text, dtTuNgay.Value.ToShortDateString(), dtDenNgay.Value.ToShortDateString());

            this.rpvVeXe.RefreshReport();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            ReportVeXe_Load(sender, e);
            txtTaiKhoan.Text = cbbBenDi.Text = "";
            dtTuNgay.Text = dtDenNgay.Text = "";
        }

        private void ReportVeXe_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
            this.Close();
        }

    }
}
